package conson.tech.manage.facade.provider;

import conson.tech.core.constant.CommonConstants;
import conson.tech.core.constant.SecurityConstants;
import conson.tech.core.response.Response;
import conson.tech.manage.scene.service.DictionaryService;
import conson.tech.manage.scene.vo.request.DictionaryRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 字典服务
 * @author: yuwenshuo
 * @since: 2020-06-22 09:58
 */


@RestController
@RequestMapping((SecurityConstants.INNERAPI + "/dictionary"))
public class DictionaryProvider {

    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 查询
     * @param dictionaryRequest
     * @return
     */
    @PostMapping("/query")
    public Response query(@RequestBody DictionaryRequest dictionaryRequest) {

        //Feign接口只查询有效的
        dictionaryRequest.setState(CommonConstants.DEL_FLAG_NORMAL);

        return Response.success(dictionaryService.getDictionaryByParam(dictionaryRequest));
    }


    /**
     * 根据值获取编码
     * @param dictionaryRequest
     * @return
     */
    @PostMapping("/code")
    public Response<Integer> getCodeByValue(@RequestBody DictionaryRequest dictionaryRequest){

        return Response.success(dictionaryService.getDictionaryByCondition(dictionaryRequest).getId());

    }


    /**
     * 根据编码获取值
     * @param dictionaryRequest
     * @return
     */
    @PostMapping("/value")
    public Response<String> getValueByCode(@RequestBody DictionaryRequest dictionaryRequest){

        return Response.success(dictionaryService.getDictionaryByCondition(dictionaryRequest).getVal());
    }



}
